/*
 *   Author:         Kirin Zhong
 *   Created Date:   2024/6/3
 *
 *   Updated Date    Updated By      Reason of Update
 *   ------------    -----------     -----------------------------------------------
 */
package org.kirin.ocr.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DateValidator {
    public static boolean isValidDate(String dateString, String dateFormat) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        sdf.setLenient(false); // 不使用宽松模式
        try {
            sdf.parse(dateString);
            return true; // 日期符合格式
        } catch (ParseException e) {
            return false; // 日期不符合格式
        }
    }

    public static void main(String[] args) {
        String inputDate = "20230412";
        String format = "yyyyMM";
        System.out.println("Date " + inputDate + " is valid: " + isValidDate(inputDate, format));
    }
}
